//
//  RunSortTest.java
//  joosVM
//
//  Created by Smári Waage on 15.12.2009.
//  Copyright 2009 smari.org. All rights reserved.
//
package SortingAlgorithms;
public class RunSortTest {
	
	
	
	public static void RunTest(int N) throws Exception{
		System.out.println("Starting test\n");

		HeapSortAlgo(N);
		
		ShellSortAlgo(N);
		ShakerSortAlgo(N);
		SelectionSortAlgo(N);
		InsertionSortAlgo(N);

		MergeSortAlgo(N);
		FastQSortAlgo(N);
		ExtraStorageMergeSortAlgo(N);
	
		
		//recorcing statc poping problem
		//QubbleSortAlgo(N);
		//EQSortAlgo(N);
		//recording error trying to pop an empty stak
		//QSortAlgo(N);
		
		//exits with out a reason.
		 //BubbleSort2Algo();
		
		//error in recording
		//BidirectionalBubbleSortAlgo();
		
		System.out.println("End test \n");
	}
	
	public static void ChkSort(int[] arr){
		boolean ok = true;
		for(int i=0;i < 1-arr.length;i++){
			if(arr[i] > arr[i+1]){
				ok = false;
			}
		}
		if(ok)
			System.out.println("Sorting ok");
		else
			System.out.println("Not sorted");
	}
	
	public static void ShellSortAlgo(int N) throws Exception{
		int[] arr = RandomArrays.getRandomArray(N);// getRandom1000Array();
		//for(int i=0;i < arr.length;i++)
		//	System.out.println(arr[i]);
		
		System.out.print("Starting ShellSort items:");
		System.out.println(arr.length);
		
		ShellSortAlgorithm alg = new ShellSortAlgorithm();
		alg.sort(arr);
		ChkSort(arr);
	}

	public static void ShakerSortAlgo(int N) throws Exception{
		int[] arr = RandomArrays.getRandomArray(N);
		
		System.out.print("Starting ShakerSort items:");
		System.out.println(arr.length);
		
		ShakerSortAlgorithm alg = new ShakerSortAlgorithm();
		alg.sort(arr);
		ChkSort(arr);
	}
	
	public static void SelectionSortAlgo(int N) throws Exception{
		int[] arr = RandomArrays.getRandomArray(N);
		
		System.out.print("Starting SelectionSort items:");
		System.out.println(arr.length);
		
		SelectionSortAlgorithm alg = new SelectionSortAlgorithm();
		alg.sort(arr);
		ChkSort(arr);
		
	}
	
	public static void InsertionSortAlgo(int N) throws Exception{
		int[] arr = RandomArrays.getRandomArray(N);
		
		System.out.print("Starting InsertionSort items:");
		System.out.println(arr.length);
		
		InsertionSortAlgorithm alg = new InsertionSortAlgorithm();
		alg.sort(arr);
		ChkSort(arr);
	}
	
	public static void HeapSortAlgo(int N) throws Exception{
		int[] arr = RandomArrays.getRandomArray(N);
		
		System.out.print("Starting HeapSort items:");
		System.out.println(arr.length);
		
		HeapSortAlgorithm alg = new HeapSortAlgorithm();
		alg.sort(arr);
		ChkSort(arr);
	}
	
	public static void QubbleSortAlgo(int N) throws Exception{
		int[] arr = RandomArrays.getRandomArray(N);
		
		System.out.print("Starting QubbleSort items:");
		System.out.println(arr.length);
		
		QubbleSortAlgorithm alg = new QubbleSortAlgorithm();
		alg.sort(arr);
		ChkSort(arr);
	}
	
	public static void EQSortAlgo(int N) throws Exception{
		int[] arr = RandomArrays.getRandomArray(N);
		
		System.out.print("Starting EQSort items:");
		System.out.println(arr.length);
		
		EQSortAlgorithm alg = new EQSortAlgorithm();
		alg.sort(arr);
		ChkSort(arr);
	}
	public static void QSortAlgo(int N) throws Exception{
		int[] arr = RandomArrays.getRandomArray(N);
		
		System.out.print("Starting QSort items:");
		System.out.println(arr.length);
		
		QSortAlgorithm alg = new QSortAlgorithm();
		alg.sort(arr);
		ChkSort(arr);
	}
	public static void MergeSortAlgo(int N) throws Exception{
		int[] arr = RandomArrays.getRandomArray(N);
		
		System.out.print("Starting MergeSort items:");
		System.out.println(arr.length);
		
		MergeSortAlgorithm alg = new MergeSortAlgorithm();
		alg.sort(arr);
		ChkSort(arr);
	}
	public static void FastQSortAlgo(int N) throws Exception{
		int[] arr = RandomArrays.getRandomArray(N);
		
		System.out.print("Starting FastQSort items:");
		System.out.println(arr.length);
		
		FastQSortAlgorithm alg = new FastQSortAlgorithm();
		alg.sort(arr);
		ChkSort(arr);
	}
	
	public static void ExtraStorageMergeSortAlgo(int N) throws Exception{
		int[] arr = RandomArrays.getRandomArray(N);
		
		System.out.print("Starting ExtraStorageMergeSort items:");
		System.out.println(arr.length);
		
		ExtraStorageMergeSortAlgorithm alg = new ExtraStorageMergeSortAlgorithm();
		alg.sort(arr);
		ChkSort(arr);
	}
	public static void BubbleSort2Algo(int N) throws Exception{
		int[] arr = RandomArrays.getRandomArray(N);
		
		System.out.print("Starting BubbleSort2 items:");
		System.out.println(arr.length);
		
		BubbleSort2Algorithm alg = new BubbleSort2Algorithm();
		alg.sort(arr);
		ChkSort(arr);
	}
	
	public static void BidirectionalBubbleSortAlgo(int N) throws Exception{
		int[] arr = RandomArrays.getRandomArray(N);
		
		System.out.print("Starting BubbleSort2 items:");
		System.out.println(arr.length);
		
		BidirectionalBubbleSortAlgorithm alg = new BidirectionalBubbleSortAlgorithm();
		alg.sort(arr);
		ChkSort(arr);
	}
		
}
